﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Condition: Write a program to sort elements by using selection sort algorithm.

class SortElements
{
    static void Main()
    {
        // 1. Declare array of N elements
        Console.Write("Enter number of elements N: ");
        int N = int.Parse(Console.ReadLine());
        int[] myArr = new int[N];
        Console.WriteLine("Enter elements of integer array: ");
        for (int index = 0; index < N; index++)
        {
            Console.Write("element[{0}]= ", index);
            myArr[index] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine();
       
     
        int min;

        // 2. Changing elements possitions

        for (int i = 0; i < N-1; i++)
        {
            min = i;
            for (int j = i+1; j < N; j++)
            {
                if (myArr[min] > myArr[j])
                {
                    min = j;
                }
                if (min != i)
                {
                    int K = myArr[i];
                    myArr[i] = myArr[min];
                    myArr[min] = K;
                }
            }
        }

        // 3. Output sorted array
        Console.WriteLine("The sorted array will look like:");
        for (int i = 0; i < N; i++)
        {
            Console.Write(myArr[i]+" ");
        }
        Console.WriteLine();

    }
}

